/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bus.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.bus.entity.Ent;
import com.thinkgem.jeesite.modules.bus.service.EntService;

/**
 * 养殖场企业信息Controller
 * @author mengying
 * @version 2019-05-29
 */
@Controller
@RequestMapping(value = "${adminPath}/bus/ent")
public class EntController extends BaseController {

	@Autowired
	private EntService entService;
	
	@ModelAttribute
	public Ent get(@RequestParam(required=false) String id) {
		Ent entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = entService.get(id);
		}
		if (entity == null){
			entity = new Ent();
		}
		return entity;
	}
	
	@RequiresPermissions("bus:ent:view")
	@RequestMapping(value = {"list", ""})
	public String list(Ent ent, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Ent> page = entService.findPage(new Page<Ent>(request, response), ent); 
		model.addAttribute("page", page);
		return "modules/bus/entList";
	}

	@RequiresPermissions("bus:ent:view")
	@RequestMapping(value = "form")
	public String form(Ent ent, Model model) {
		model.addAttribute("ent", ent);
		return "modules/bus/entForm";
	}
	@RequiresPermissions("bus:ent:edit")
	@RequestMapping(value = "save")
	public String save(Ent ent, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, ent)){
			return form(ent, model);
		}
		entService.save(ent);
		addMessage(redirectAttributes, "保存养殖场企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/bus/ent/?repage";
	}

	
	@RequiresPermissions("bus:ent:edit")
	@RequestMapping(value = "delete")
	public String delete(Ent ent, RedirectAttributes redirectAttributes) {
		entService.delete(ent);
		addMessage(redirectAttributes, "删除养殖场企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/bus/ent/?repage";
	}
	/**
	 *养殖场信息查看
	 * @author mengying
	 * @param ent
	 * @return String
	 */
	@RequiresPermissions("bus:ent:view")
	@RequestMapping(value = "viewFarmInfo")
	public String viewFarmInfo(Ent ent,HttpServletRequest request, HttpServletResponse response,Model model) {
		Page<Ent> page = entService.viewFarmInfo(new Page<Ent>(request, response),ent);
		model.addAttribute("page", page);
		return "modules/bus/entAuditView";
	}
}